<?php
/**
 * default template file for Categories view of iTOEstate component
 * @package		iTO
 * @subpackage	Components
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @author		Kostyantyn Didenko
 * @license		License GNU General Public License version 2 or later
 */
 
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import the Joomla modellist library
jimport('joomla.application.component.modellist');

/**
 * iTOEstate Model
 */
class iTOEstateModelCategories extends JModelList
{

	/**
	 * Method to build an SQL query to load the list data.
	 *
	 * @return	string	An SQL query
	 */
	protected function getListQuery() 
	{		
		// Create a new query object.
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('c.id, c.alias, c.state, c.crdate');
		$query->from('#__itoestate_categories AS c');
		
		// Check for filter search
		$search = $this->getState('filter.search');
		if (!empty($search)) {
			$query->where('(l.alias LIKE "%'.$search.'%")');
		}
		
		// Do default ordering
		$query->order('c.id ASC');
		
		return $query;
	}
	
	/**
	 * Method to populate the model states.
	 *
	 * @return	void
	 */
	protected function populateState($ordering = null, $direction = null)
	{
		// Initialise variables.
		$app = JFactory::getApplication('administrator');

		// Load the search filter state.
		$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
		$this->setState('filter.search', $search);

		/*$state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string');
		$this->setState('filter.state', $state);*/

		$categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', '');
		$this->setState('filter.category_id', $categoryId);

		/*$typeId = $this->getUserStateFromRequest($this->context.'.filter.type_id', 'filter_type_id', '');
		$this->setState('filter.type_id', $clientId);

		$regionId = $this->getUserStateFromRequest($this->context.'.filter.region_id', 'filter_region_id', '');
		$this->setState('filter.region_id', $language);

		// Load the parameters.
		$params = JComponentHelper::getParams('com_itoestate');
		$this->setState('params', $params);*/

		// List state information.
		parent::populateState('c.id', 'desc');
	}
	 
}
